<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>编辑字段</title>
  <meta name="renderer" content="webkit"> 
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">  
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"> 
  <meta name="apple-mobile-web-app-status-bar-style" content="black"> 
  <meta name="apple-mobile-web-app-capable" content="yes">  
  <meta name="format-detection" content="telephone=no"> 
  <link rel="stylesheet" type="text/css" href="/Public/admin/layui/css/layui.css" media="all">
  <link rel="stylesheet" type="text/css" href="/Public/admin/bootstrap/css/bootstrap.css" media="all">
  <link rel="stylesheet" type="text/css" href="/Public/admin/global.css" media="all">
  <link rel="stylesheet" type="text/css" href="/Public/admin/css/personal.css" media="all">
</head>
<body>
<div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
  <div class="layui-tab-content">
    <div class="layui-tab-item layui-show">
      <a href="/admin/model"><button class="layui-btn layui-btn-danger">返回模型列表</button></a>
      <a href="/admin/field/index/modelid/<?php echo ($modelid); ?>"><button class="layui-btn"><i class="layui-icon">&#xe60a;</i>字段列表</button></a>
      <a href="/admin/field/priview/modelid/<?php echo ($modelid); ?>" target="_blank"><button class="layui-btn layui-btn-normal">预览模型</button></a>
      <form class="layui-form" action="/admin/field/edit" method="post">
      <input name="modelid" type="hidden" value="<?php echo ($modelid); ?>">
      <input name="fieldid" type="hidden" value="<?php echo ($fieldid); ?>">
        <table class="layui-table">
          <colgroup>
            <col width="350">
            <col>
          </colgroup>
          <thead>
            <tr>
              <th colspan="2"><label>字段属性</label></th>
            </tr> 
          </thead>
          <tbody>
            <tr>
              <td><label>字段类型</label></td>
              <td>
                <div class="layui-input-inline">
                   <select lay-filter="ftyp" name="formtype">
                     <option value="">请选择字段类型</option>
                     <?php if(is_array($all_field)): $i = 0; $__LIST__ = $all_field;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vo): $mod = ($i % 2 );++$i;?><option value="<?php echo ($key); ?>" <?php if($data['formtype'] == $key): ?>selected<?php endif; ?>><?php echo ($vo); ?></option><?php endforeach; endif; else: echo "" ;endif; ?>
                   </select>
               </div>
              </td>
            </tr>
            <tr>
              <td>
                <font color="red">*</font>
                <label>字段名</label>
                <br>
                只能由英文字母、数字和下划线组成，并且仅能字母开头，不以下划线结尾 
              </td>
              <td>
                <div class="layui-input-inline">
                    <input name="field" required lay-verify="required" autocomplete="off" class="layui-input" type="text" value="<?php echo ($data["field"]); ?>">
                </div>
              </td>
            </tr>
            <tr>
              <td>
                <font color="red">*</font>
                <label>字段别名</label>
                <br>
                例如：文章标题
              </td>
              <td>
                <div class="layui-input-inline">
                    <input name="name" required lay-verify="required" autocomplete="off" value="<?php echo ($data["name"]); ?>" class="layui-input" type="text">
                </div>
              </td>
            </tr>
            <tr>
              <td>
                <label>字段提示</label>
                <br>
                显示在字段别名下方作为表单输入提示
              </td>
              <td>
                <textarea name="tips" placeholder="请输入" class="layui-textarea"><?php echo ($data["tips"]); ?></textarea>
              </td>
            </tr>
            <tr>
              <td>
                <label>相关参数</label>
                <br>
                设置表单相关属性
              </td>
              <td id="setting"><?php echo ($form_data); ?></td>
            </tr>
            <tr>
              <td>
                <label>字符长度取值范围</label>
                <br>
                系统将在表单提交时检测数据长度范围是否符合要求，如果不想限制长度请留空
              </td>
              <td>
                  <div class="layui-inline">
                    最小值：
                    <div class="layui-input-inline">
                      <input class="layui-input" name="minlength" value="<?php echo ($data["minlength"]); ?>" size="5" type="text">
                    </div>
                  </div>
                  <label>&nbsp;&nbsp;</label>
                  <div class="layui-inline">
                    最大值：
                    <div class="layui-input-inline">
                      <input class="layui-input" name="maxlength" value="<?php echo ($data["maxlength"]); ?>" size="5" type="text">
                    </div>
                  </div>
              </td>
            </tr>
            <tr>
              <td>
                <label>数据校验正则</label>
                <br>
                系统将通过此正则校验表单提交的数据合法性，如果不想校验数据请留空
              </td>
              <td>
                <div class="layui-input-inline" style="width: 250px;">
                  <input class="layui-input" id="pattern" name="pattern" value="<?php echo ($data["pattern"]); ?>" size="5" type="text">
                </div>
                <div class="layui-input-inline">
                   <select lay-filter="patsele" name="pattern_select">
                     <option value="">请选择字段类型</option>
                     <option value="">常用正则</option>
                     <option value="/^[0-9.-]+$/">数字</option>
                     <option value="/^[0-9-]+$/">整数</option>
                     <option value="/^[a-z]+$/i">字母</option>
                     <option value="/^[0-9a-z]+$/i">数字+字母</option>
                     <option value="/^[\w\-\.]+@[\w\-\.]+(\.\w+)+$/">E-mail</option>
                     <option value="/^[0-9]{5,20}$/">QQ</option>
                     <option value="/^http:\/\//">超级链接</option>
                     <option value="/^(1)[0-9]{10}$/">手机号码</option>
                     <option value="/^[0-9-]{6,13}$/">电话号码</option>
                   </select>
               </div>
              </td>
            </tr>
            <tr>
              <td>
                <label>数据校验未通过的提示信息</label>
              </td>
              <td>
                <div class="layui-input-inline" style="width: 250px;">
                    <input name="errortips" value="<?php echo ($data["errortips"]); ?>" size="50" autocomplete="off" class="layui-input" type="text">
                </div>
              </td>
            </tr>
            <tr>
              <td>
                <label>值唯一</label>
              </td>
              <td>
                  <div class="layui-input-inline">
                    <input name="isunique" value="1" title="是" type="radio" <?php if($data['isunique'] == '1'): ?>checked<?php endif; ?>>
                    <input name="isunique" value="0" title="否" type="radio" <?php if($data['isunique'] == '0'): ?>checked<?php endif; ?>>
                  </div>
              </td>
            </tr>
            <tr>
              <td>
                <label>作为基本信息</label>
                <br />
                基本信息将在添加页面左侧显示
              </td>
              <td>
                  <div class="layui-input-inline">
                    <input name="isbase" value="1" title="是" type="radio"  <?php if($data['isbase'] == '1'): ?>checked<?php endif; ?>>
                    <input name="isbase" value="0" title="否" type="radio"  <?php if($data['isbase'] == '0'): ?>checked<?php endif; ?>>
                  </div>
              </td>
            </tr>
            <tr>
              <td>
                <label>作为搜索条件</label>
              </td>
              <td>
                  <div class="layui-input-inline">
                    <input name="issearch" value="1" title="是" type="radio" <?php if($data['issearch'] == '1'): ?>checked<?php endif; ?>>
                    <input name="issearch" value="0" title="否" type="radio" <?php if($data['issearch'] == '0'): ?>checked<?php endif; ?>>
                  </div>
              </td>
            </tr>
            <tr>
              <td>
                <label>在前台投稿中显示</label>
              </td>
              <td>
                  <div class="layui-input-inline">
                    <input name="isadd" value="1" title="是" type="radio" <?php if($data['isadd'] == '1'): ?>checked<?php endif; ?>>
                    <input name="isadd" value="0" title="否" type="radio" <?php if($data['isadd'] == '2'): ?>checked<?php endif; ?>>
                  </div>
              </td>
            </tr>
            <tr>
              <td>
                <label>作为全站搜索信息</label>
              </td>
              <td>
                  <div class="layui-input-inline">
                    <input name="isfulltext" value="1" title="是" type="radio" <?php if($data['isfulltext'] == '1'): ?>checked<?php endif; ?>>
                    <input name="isfulltext" value="0" title="否" type="radio" <?php if($data['isfulltext'] == '0'): ?>checked<?php endif; ?>>
                  </div>
              </td>
            </tr>
            <tr>
              <td>
                <label>在推荐位标签中调用</label>
              </td>
              <td>
                  <div class="layui-input-inline">
                    <input name="isposition" value="1" title="是" type="radio" <?php if($data['isposition'] == '1'): ?>checked<?php endif; ?>>
                    <input name="isposition" value="0" title="否" type="radio" <?php if($data['isposition'] == '0'): ?>checked<?php endif; ?>>
                  </div>
              </td>
            </tr>
          </tbody>
        </table>
        <div class="layui-input-block">
          <button class="layui-btn" lay-submit>提交</button>
          <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
      </form>
    </div>
  </div>
</div>
<script type="text/javascript" src="/Public/admin/layui/layui.js"></script>
<script>
layui.use('form', function(){
  var form = layui.form();
  form.on('select(ftyp)', function(data){
    if (data.value == "") {
      document.getElementById("setting").innerHTML="";
      return;
    }
    if (window.XMLHttpRequest)
    {
      // IE7+, Firefox, Chrome, Opera, Safari 浏览器执行的代码
      xmlhttp=new XMLHttpRequest();
    }
    else
    {
      //IE6, IE5 浏览器执行的代码
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange=function()
    {
      if (xmlhttp.readyState==4 && xmlhttp.status==200)
      {
        document.getElementById("setting").innerHTML=xmlhttp.responseText;
        form.render();
      }
    }
    xmlhttp.open("GET","/admin/field/getFieldPath/type/"+data.value,true);
    xmlhttp.send();
  });
  form.on('select(patsele)', function(data){
    if (data.value == "") {
      document.getElementById("pattern").value="";
      return;
    }
    document.getElementById("pattern").value=data.value;
  });
  form.on('radio(colshow)', function(data){
    document.getElementById("setcols").style.display='';
    document.getElementById("setsize").style.display='none';
    form.render();
  });
  form.on('radio(sizeshow)', function(data){
    document.getElementById("setcols").style.display='none';
    document.getElementById("setsize").style.display='';
    form.render();
  });
  form.on('select(minnumshow)', function(data){
    console.log(data.value); //得到被选中的值
    if(data.value!='varchar') {
      document.getElementById("minnumber").style.display='';
    } else {
      document.getElementById("minnumber").style.display='none';
    }
  });
});
</script>
</body>
</html>